package com.ruoyi.web.controller.iot;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.iot.domain.IotMonitor;
import com.ruoyi.iot.service.IIotMonitorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监控Controller
 *
 * @author 陈江灿
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/iot/monitor")
public class IotMonitorController extends BaseController {
    @Autowired
    private IIotMonitorService iotMonitorService;

    /**
     * 查询监控列表
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotMonitor iotMonitor) {
        startPage();
        List<IotMonitor> list = iotMonitorService.selectIotMonitorList(iotMonitor);
        return getDataTable(list);
    }

    /**
     * 导出监控列表
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:export')")
    @Log(title = "监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotMonitor iotMonitor) {
        List<IotMonitor> list = iotMonitorService.selectIotMonitorList(iotMonitor);
        ExcelUtil<IotMonitor> util = new ExcelUtil<IotMonitor>(IotMonitor.class);
        util.exportExcel(response, list, "监控数据");
    }

    /**
     * 获取监控详细信息
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:query')")
    @GetMapping(value = "/{monitorId}")
    public AjaxResult getInfo(@PathVariable("monitorId") Long monitorId) {
        return success(iotMonitorService.selectIotMonitorByMonitorId(monitorId));
    }

    /**
     * 新增监控
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:add')")
    @Log(title = "监控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotMonitor iotMonitor) {
        return toAjax(iotMonitorService.insertIotMonitor(iotMonitor));
    }

    /**
     * 修改监控
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:edit')")
    @Log(title = "监控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotMonitor iotMonitor) {
        return toAjax(iotMonitorService.updateIotMonitor(iotMonitor));
    }

    /**
     * 删除监控
     */
    @PreAuthorize("@ss.hasPermi('iot:monitor:remove')")
    @Log(title = "监控", businessType = BusinessType.DELETE)
    @DeleteMapping("/{monitorIds}")
    public AjaxResult remove(@PathVariable Long[] monitorIds) {
        return toAjax(iotMonitorService.deleteIotMonitorByMonitorIds(monitorIds));
    }
}
